function insertBanner(bannerJson) { jQuery('div#centralNotice').prepend( bannerJson.banner ); } function toggleNotice() { var notice = document.getElementById('centralNotice'); if (!wgNoticeToggleState) { notice.className = notice.className.replace('collapsed', 'expanded'); toggleNoticeCookie('0'); } else { notice.className = notice.className.replace('expanded', 'collapsed'); toggleNoticeCookie('1'); } wgNoticeToggleState = !wgNoticeToggleState; } function toggleNoticeStyle(elems, display) { if(elems) for(var i=0;i'; $( '#siteNotice' ).prepend( '
'+bannerScript+'
' ); }, 'loadBannerList': function( geoOverride ) { if ( geoOverride ) { var geoLocation = geoOverride; // override the geo info } else { var geoLocation = Geo.country; // pull the geo info } var bannerListQuery = $.param( { 'language': wgContentLanguage, 'project': wgNoticeProject, 'country': geoLocation } ); var bannerListURL = wgScript + '?title=' + encodeURIComponent('Spécial:BannerListLoader') + '&cache=/cn.js&' + bannerListQuery; var request = $.ajax( { url: bannerListURL, dataType: 'json', success: $.centralNotice.fn.chooseBanner } ); }, 'chooseBanner': function( bannerList ) { // Convert the json object to a true array bannerList = Array.prototype.slice.call( bannerList ); // Make sure there are some banners to choose from if ( bannerList.length == 0 ) return false; var groomedBannerList = []; for( var i = 0; i < bannerList.length; i++ ) { // Only include this banner if it's intended for the current user if( ( wgUserName && bannerList[i].display_account ) || ( !wgUserName && bannerList[i].display_anon == 1 ) ) { // add the banner to our list once per weight for( var j=0; j < bannerList[i].weight; j++ ) { groomedBannerList.push( bannerList[i] ); } } } // Return if there's nothing left after the grooming if( groomedBannerList.length == 0 ) return false; // Load a random banner from our groomed list $.centralNotice.fn.loadBanner( groomedBannerList[ Math.floor( Math.random() * groomedBannerList.length ) ].name ); }, 'getQueryStringVariables': function() { document.location.search.replace( /\??(?:([^=]+)=([^&]*)&?)/g, function () { function decode( s ) { return decodeURIComponent( s.split( "+" ).join( " " ) ); } $.centralNotice.data.getVars[decode( arguments[1] )] = decode( arguments[2] ); } ); } } } $( document ).ready( function () { // Initialize the query string vars $.centralNotice.fn.getQueryStringVariables(); if( $.centralNotice.data.getVars['banner'] ) { // if we're forcing one banner $.centralNotice.fn.loadBanner( $.centralNotice.data.getVars['banner'] ); } else { // Look for banners ready to go NOW $.centralNotice.fn.loadBannerList( $.centralNotice.data.getVars['country'] ); } } ); //document ready } )( jQuery );